/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.DAO;

import com.Entity.Employee;
import com.Entity.EmployeeTests;
import com.Interface.EmployeeTestsInterface;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 *
 * @author Vi
 */
@Stateless
public class EmployeeTestsDAO implements EmployeeTestsInterface {

    private EntityManager entityManager;

    public EmployeeTestsDAO() {
        EntityManagerFactory factory = Persistence.createEntityManagerFactory("persistenceUnit");
        entityManager = factory.createEntityManager();
    }

    @Override
    public EmployeeTests getEmployeeTest(int idEmployee) {
        return (EmployeeTests) entityManager.createQuery("select et from EmployeeTests et where et.idEmployee = " + idEmployee).getSingleResult();
    }

    @Override
    public void addEmployeeTests(EmployeeTests emp) {
        entityManager.getTransaction().begin();
        entityManager.persist(emp);
        entityManager.getTransaction().commit();
    }

    @Override
    public void updateEmploteeTest(EmployeeTests emp) {
        EmployeeTests actual = getEmployeeTest(emp.getIdEmployee().getIdEmployee());
        entityManager.getTransaction().begin();
        entityManager.persist(actual);
        actual.setPunctuality(emp.getPunctuality());
        actual.setPlanning(emp.getPlanning());
        actual.setDecisionMaking(emp.getDecisionMaking());
        actual.setManagementPeople(emp.getManagementPeople());
        actual.setCommunications(emp.getCommunications());
        actual.setCreativity(emp.getCreativity());
        actual.setResistanceStress(emp.getResistanceStress());
        entityManager.getTransaction().commit();
    }

}
